#include <STC15F2K60S2.H>
#include "Timer.h"
#include "SMG.h"
#include "Key.h"
#include "onewire.h"
#include "ds1302.h"

unsigned char temperature_read_time_flag;

void main()
{
	STC15_Power_All_Init();
	Timer2_Init();
	DS1302_Init();
	DS1302_SetTime();
	
	while(1)
	{
		SMG_Show_Data();	//数码管显示
		Key4_Proc();		//按键扫描
		DS1302_ReadTime();
		
		if (temperature_read_time_flag == 1)	//温度读取
		{
			temperature_read_time_flag = 0;
			f_Temperature = DS18B20_GetTemperature();
		}
		
	}
	
}



// 定时器2 中断服务函数模板
void Timer2_Routine() interrupt 12  // 1T 16位自动重载
{
	static unsigned char i, smg_scan_cnt;	//数码管
	static unsigned char key4_count;	//独立按键
	static unsigned int  Temperature_cnt;
	
	ui_ChangAn_ms++;
	
	
	smg_scan_cnt++;				//数码管扫描时间
	if (smg_scan_cnt >= 1)		//2ms扫描一次数码管
	{
		smg_scan_cnt = 0;		//软件复位
		P2 = 0xE0; P0 = 0xFF;	//定时器扫描数码管，先消影，就不会出现残影了!!！
		P2 = 0xC0; P0 = 0x01<<i;
		
		if (menu_index == 0) {P2 = 0xE0; P0 = menu1[i]; P2 = 0;}
		if (menu_index == 1) {P2 = 0xE0; P0 = menu2[i]; P2 = 0;}
		if (menu_index == 2) {P2 = 0xE0; P0 = menu3[i]; P2 = 0;}
//		if (menu_index == 3) {P2 = 0xE0; P0 = menu4[i]; P2 = 0;}
//		if (menu_index == 4) {P2 = 0xE0; P0 = menu5[i]; P2 = 0;}
//		if (menu_index == 5) {P2 = 0xE0; P0 = menu6[i]; P2 = 0;}
		i ++;
		i = i % 8;
	}
	
	if (++key4_count >= 10)	//独立按键的扫描
	{
		key4_count = 0;
		uc_Key_flag = 0;
	}
	
	if (++Temperature_cnt >= 900)	//小于1s读取一次
	{
		Temperature_cnt = 0;
		temperature_read_time_flag = 1;
	}

}

